{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "cap = cv2.VideoCapture(\"small_nightRoad.mp4\")\n",
    "vidsize = (640,480,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Gamma Correction Function\n",
    "def gamma_correction(RGBimage, correct_param = 0.35,equalizeHist = False):\n",
    "    red = RGBimage[:,:,2]\n",
    "    green = RGBimage[:,:,1]\n",
    "    blue = RGBimage[:,:,0]\n",
    "    \n",
    "    red = red/255.0\n",
    "    red = cv2.pow(red, correct_param)\n",
    "    red = np.uint8(red*255)\n",
    "    if equalizeHist:\n",
    "        red = cv2.equalizeHist(red)\n",
    "    \n",
    "    green = green/255.0\n",
    "    green = cv2.pow(green, correct_param)\n",
    "    green = np.uint8(green*255)\n",
    "    if equalizeHist:\n",
    "        green = cv2.equalizeHist(green)\n",
    "        \n",
    "    \n",
    "    blue = blue/255.0\n",
    "    blue = cv2.pow(blue, correct_param)\n",
    "    blue = np.uint8(blue*255)\n",
    "    if equalizeHist:\n",
    "        blue = cv2.equalizeHist(blue)\n",
    "    \n",
    "\n",
    "    output = cv2.merge((blue,green,red))\n",
    "    return output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#GAMMA CORRECTION\n",
    "cv2.namedWindow('input')\n",
    "cv2.namedWindow('output')\n",
    "colors = np.zeros((3))\n",
    "\n",
    "out = np.zeros_like((vidsize))\n",
    "\n",
    "while cap.isOpened():\n",
    "    ret,image_np = cap.read()\n",
    "    if ret == True:\n",
    "        goruntu = gamma_correction(image_np)\n",
    "        cv2.imshow('input', image_np)\n",
    "        cv2.imshow('output', goruntu)\n",
    "        if cv2.waitKey(25) & 0xFF == ord('q'):\n",
    "            cv2.destroyAllWindows()\n",
    "            break\n",
    "    else:\n",
    "        break\n",
    " \n",
    "\n",
    "\n",
    "cap.release()               \n",
    "cv2.destroyAllWindows()        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
